var param_platform_code = $.url().param('platform_code');
var param_date = $.url().param('date');

getTypeInfo(param_platform_code, param_date);

function getTypeInfo(platform_code, date) {
    $("#type_loading_zone").show();
    $("#type_data_zone").hide();
    $("#type_error_zone").hide();
    var token = getCookie('csrftoken');
    $.ajax({
        // url: '/football/get_type_info/',
        url: 'http://8.134.215.241:9080/jyb/core/plat/acquireplattypes',
        type: 'POST',
        headers:{'X-CSRFToken': token, "Content-Type": "application/json"},
        data: JSON.stringify({'baseDate': date, 'platCode': platform_code}),
        success: function(data) {
            let jsonData = data['result']['platTypeVoList'];
            console.log(jsonData);
            let listHtml = "";
            listHtml = listHtml + '<div class="self_common_zone">';
            jsonData.forEach((item, index) => {
                let type_code = item['typeCode'];
                let type_name = item['typeName'];
                listHtml = listHtml + '<div data-date="' + date + '" data-platform="' + platform_code + '" data-type="' + type_code + '" onclick="goToLeaguePage(this)" class="self_common_item self_common_item_size_normal self_letter_spacing_2">';
                listHtml = listHtml + '<span>';
                listHtml = listHtml + type_name;
                listHtml = listHtml + '</span>';
                listHtml = listHtml + '</div>';
            });
            listHtml = listHtml + '</div>';
            $("#type_data_zone").html(listHtml);
            $("#type_loading_zone").hide();
            $("#type_error_zone").hide();
            $("#type_data_zone").show();
        },
        error: function() {
            $("#type_loading_zone").hide();
            $("#type_data_zone").hide();
            $("#type_error_zone").show();
        }
    });
}

function goToLeaguePage(element) {
    const type_code = element.dataset.type;
    const platform_code = element.dataset.platform;
    const date = element.dataset.date;
    goToOtherPage('./league.html?platform_code=' + platform_code + '&type_code=' + type_code + '&date=' + date );
}

function navigateToPlatformPage() {
    goToOtherPage('./platform.html?date=' + param_date );
}